﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DAL;

namespace BLL
{
    public class BTaxiGpsHistory
    {
        private readonly DAL.DTaxiGpsHistory _dTaxiGpsHistory = new DTaxiGpsHistory();



        #region  Method

        public bool Add(Model.TaxiGpsHistoryInfo model)
        {
            return _dTaxiGpsHistory.Add(model);
        }

        public  int AddList(string sql)
        {
            return _dTaxiGpsHistory.AddList(sql);
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return _dTaxiGpsHistory.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return _dTaxiGpsHistory.Exists(id);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.TaxiGpsHistoryInfo model)
        {
            return _dTaxiGpsHistory.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return _dTaxiGpsHistory.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return _dTaxiGpsHistory.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.TaxiGpsHistoryInfo GetModel(int id)
        {

            return _dTaxiGpsHistory.GetModel(id);
        }

        ///// <summary>
        ///// 得到一个对象实体，从缓存中
        ///// </summary>
        //public Model.TaxiGpsHistoryInfo GetModelByCache(int id)
        //{

        //    string CacheKey = "ttaxigpshistoryModel-" + id;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = _dTaxiGpsHistory.GetModel(id);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (Model.TaxiGpsHistoryInfo)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return _dTaxiGpsHistory.GetList(strWhere);
        }

        public DataSet GetList(string driverPhoneNumber, DateTime startTime,DateTime endTime)
        {
            return _dTaxiGpsHistory.GetList(driverPhoneNumber,startTime,endTime);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.TaxiGpsHistoryInfo> GetModelList(string strWhere)
        {
            DataSet ds = _dTaxiGpsHistory.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.TaxiGpsHistoryInfo> DataTableToList(DataTable dt)
        {
            List<Model.TaxiGpsHistoryInfo> modelList = new List<Model.TaxiGpsHistoryInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.TaxiGpsHistoryInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.TaxiGpsHistoryInfo();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["DriverPhoneNumber"] != null && dt.Rows[n]["DriverPhoneNumber"].ToString() != "")
                    {
                        model.DriverPhoneNumber = dt.Rows[n]["DriverPhoneNumber"].ToString();
                    }
                    if (dt.Rows[n]["Longitude"] != null && dt.Rows[n]["Longitude"].ToString() != "")
                    {
                        model.Longitude = double.Parse(dt.Rows[n]["Longitude"].ToString());
                    }
                    if (dt.Rows[n]["Latitude"] != null && dt.Rows[n]["Latitude"].ToString() != "")
                    {
                        model.Latitude = double.Parse(dt.Rows[n]["Latitude"].ToString());
                    }
                    if (dt.Rows[n]["time"] != null && dt.Rows[n]["time"].ToString() != "")
                    {
                        model.Time = DateTime.Parse(dt.Rows[n]["time"].ToString());
                    }
                    if (dt.Rows[n]["Taxistate"] != null && dt.Rows[n]["Taxistate"].ToString() != "")
                    {
                        model.Taxistate = byte.Parse(dt.Rows[n]["Taxistate"].ToString());
                    }
                    if (dt.Rows[n]["image"] != null && dt.Rows[n]["image"].ToString() != "")
                    {
                        model.Image = (byte[])dt.Rows[n]["image"];
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获取载客率、空载率统计
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetStatisticsList(string strWhere)
        {
            return _dTaxiGpsHistory.GetStatisticsList(strWhere);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return _dTaxiGpsHistory.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return _dTaxiGpsHistory.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }


         public DataSet GetStatisResult(int intObject, string strValue, 
            int dateType,string strWhere)
         {
             return _dTaxiGpsHistory.GetStatisResult(intObject,strValue,dateType,strWhere);
         }

         public DataSet GetTaxiOnlineCountReport(string strWhere)
         {
              return _dTaxiGpsHistory.GetTaxiOnlineCountReport(strWhere);
         }


        #endregion  Method
    }
}
